package com.jml.springmvc.servlet007.config;

import com.jml.springmvc.servlet007.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;


@Configuration
@ComponentScan("com.jml.springmvc.servlet007.controller")
@EnableWebMvc
public class SpringMvcConfig implements WebMvcConfigurer {
	//配置视图解析器
	@Bean
	public InternalResourceViewResolver getInternalResourceViewResolver(){
		InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
		//前后缀
		internalResourceViewResolver.setPrefix("/WEB-INF/view/");
		internalResourceViewResolver.setSuffix(".jsp");
		return internalResourceViewResolver;
	}
	// 1.手动注入拦截器到Spring中
	@Bean
	public TokenInterceptor tokenInterceptor() {
		return new TokenInterceptor();
	}
	// 2.添加拦截器
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(tokenInterceptor()).addPathPatterns("/**");// 拦截所有的请求
	}
	// 配置springmvc相关一些信息WebMvcConfigurationSupport web视图相关内容
}
